<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将域名转换为 IDNA ASCII 格式</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ref.intl.idn.html">« IDN 函数</a></li>
      <li style="float: right;"><a href="function.idn-to-utf8.html">idn_to_utf8 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.intl.idn.html">IDN 函数</a></li>
    <li>将域名转换为 IDNA ASCII 格式</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.idn-to-ascii" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">idn_to_ascii</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.2, PECL idn &gt;= 0.1)</p><p class="refpurpose"><span class="refname">idn_to_ascii</span> &mdash; <span class="dc-title">将域名转换为 IDNA ASCII 格式 </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.idn-to-ascii-description">
  <h3 class="title">说明</h3>
  <p class="para">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>idn_to_ascii</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$domain</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = IDNA_DEFAULT</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$variant</code><span class="initializer"> = INTL_IDNA_VARIANT_UTS46</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$idna_info</code><span class="initializer"> = ?</span></span><br>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   该函数可以将 Unicode 域名转换为 IDNA ASCII 兼容格式。
  </p> 
  </div>


 <div class="refsect1 parameters" id="refsect1-function.idn-to-ascii-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">domain</code></dt>

     <dd>

      <p class="para">
       要转换的域，必须使用 UTF-8 编码。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       转换选项 — IDNA_* 开头的常量（除 IDNA_ERROR_* 开头的常量）。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">variant</code></dt>

     <dd>

      <p class="para">
       对于 IDNA 2003 是 <strong><code>INTL_IDNA_VARIANT_2003</code></strong> (自 PHP 7.2.0 起已弃用)，
       对于 UTS #46 是 <strong><code>INTL_IDNA_VARIANT_UTS46</code></strong> (仅 ICU 4.6 起可用)。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">idna_info</code></dt>

     <dd>

      <p class="para">
       仅当 <strong><code>INTL_IDNA_VARIANT_UTS46</code></strong> 用于 <code class="parameter">variant</code> 时，才可以使用该参数。
       在这种情况下，它将用这些键组成的数组来填充：
       <code class="literal">&#039;result&#039;</code> 键，转换结果（有可能是一个非法结果）；
       <code class="literal">&#039;isTransitionalDifferent&#039;</code> 键，布尔值，指示使用 UTS #46 的过滤机制是否会改变结果；
       <code class="literal">&#039;errors&#039;</code> 键，是 IDNA_ERROR_* 常量集里一个常量对应的 <span class="type">int</span> 。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.idn-to-ascii-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   IDNA ASCII 兼容格式编码的域名，  或者在失败时返回 <strong><code>false</code></strong>
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.idn-to-ascii-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.4.0</td>
       <td>
        现在 <code class="parameter">variant</code> 的默认值为 <strong><code>INTL_IDNA_VARIANT_UTS46</code></strong> ，
        而不是已弃用的 <strong><code>INTL_IDNA_VARIANT_2003</code></strong> 。
       </td>
      </tr>

      <tr>
       <td>7.2.0</td>
       <td>
        <strong><code>INTL_IDNA_VARIANT_2003</code></strong> 已被弃用；
        可以使用 <strong><code>INTL_IDNA_VARIANT_UTS46</code></strong> 代替。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-function.idn-to-ascii-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-2487">
   <p><strong>示例 #1 <span class="function"><strong>idn_to_ascii()</strong></span> 示例</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">idn_to_ascii</span><span style="color: #007700">(</span><span style="color: #DD0000">'täst.de'</span><span style="color: #007700">);&nbsp;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
  <p class="para">以上例程会输出：</p>
  <div class="example-contents screen">
<div class="cdata"><pre>
xn--tst-qla.de
</pre></div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.idn-to-ascii-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.idn-to-utf8.html" class="function" rel="rdfs-seeAlso">idn_to_utf8()</a> - 将域名从 IDNA ASCII 转换为 Unicode</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>